

% convenience function to batch track and save all the RBC velocity movies
% in a directory
function batchCapillaryBloodflowAnalysis_v2_1(autoselect)

if nargin < 1
    autoselect = false;
end

if true        %set this to true if you want the results displayed
    plotfig = figure;
else
    plotfig = [];
end
if ~autoselect
    fn = uigetfile('*.mat','select kymographs','MultiSelect', 'on');
else
    fn = dir('*kymograph.mat');
end
if isa(fn,'cell')
    for n = 1:length(fn)
        temp.name = fn{n};
        results = capillaryBloodFlow_analysis_v2_1(temp,plotfig);
        save(strrep(fn{n},'kymograph.mat','trackingResults.mat'),'results');
    end
elseif isa(fn,'char')
    temp.name = fn;
    results = capillaryBloodFlow_analysis_v2_1(temp,plotfig);
    save(strrep(fn,'kymograph.mat','trackingResults.mat'),'results');
elseif isa(fn,'struct')
    for n = 1:length(fn)
        temp.name = fn(n).name;
        results = capillaryBloodFlow_analysis_v2_1(temp,plotfig);
        save(strrep(fn(n).name,'kymograph.mat','trackingResults.mat'),'results');
    end
end
    
           